/*
 * Copyright 2011 Impetus Infotech.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.impetus.teamplan.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.OneToMany;

import com.impetus.kundera.api.ColumnFamily;
import com.impetus.kundera.api.Document;

/**
 * <Provide Type description>
 * @author amresh.singh
 */
@Entity
@Document(name="Members", db="TeamPlans")
//@ColumnFamily(family="Members", keyspace="TeamPlans")
public class Member implements Serializable {		
	
	public Member() {		
	}

	@Id
	@Column(name="member_id")
	String memberId;
	
	@Column(name = "memberName")
	String memberName; 
	
	@Column(name = "password")
	String password;
	
	
	@Column(name = "memberType")
	String memberType;
	
	@OneToMany (cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
	private List<Responsibility> responsibilities = new ArrayList<Responsibility>();
	
	@OneToMany (cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
	private List<Accomplishment> accomplishments = new ArrayList<Accomplishment>();
    
	private String responsibilitiesStr;
	

	public String getMemberId() {
		return memberId;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

	public String getMemberName() {
		return memberName;
	}

	public void setMemberName(String memberName) {
		this.memberName = memberName;
	}	

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getMemberType() {
		return memberType;
	}

	public void setMemberType(String memberType) {
		this.memberType = memberType;
	}

	public List<Responsibility> getResponsibilities() {
		return responsibilities;
	}

	public void setResponsibilities(List<Responsibility> responsibilities) {
		this.responsibilities = responsibilities;
	}

	public List<Accomplishment> getAccomplishments() {
		return accomplishments;
	}

	public void setAccomplishments(List<Accomplishment> accomplishments) {
		this.accomplishments = accomplishments;
	}	

	/**
	 * @return the responsibilitiesStr
	 */
	public String getResponsibilitiesStr() {
		return responsibilitiesStr;
	}

	/**
	 * @param responsibilitiesStr the responsibilitiesStr to set
	 */
	public void setResponsibilitiesStr(String responsibilitiesStr) {
		this.responsibilitiesStr = responsibilitiesStr;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((memberId == null) ? 0 : memberId.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof Member))
            return false;
        Member other = (Member) obj;
        if (memberId == null) {
            if (other.memberId != null)
                return false;
        } else if (!memberId.equals(other.memberId))
            return false;
        return true;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Member:\nMember Id:");
		builder.append(memberId);
		builder.append("\nMember Name:");
		builder.append(memberName);	
		builder.append("\nMember Type:");
		builder.append(memberType);	
		builder.append("\nPassword:");
		builder.append(password);	
		builder.append("\nResponsibilities:\n------------");
		for(int i = 0; i < responsibilities.size(); i++) {
			builder.append(responsibilities.get(i));
		}
		
		builder.append("\n\nAccomplishments:\n----------------");
		for(int i = 0; i < accomplishments.size(); i++) {
			builder.append("\n" + accomplishments.get(i));
		}
		return builder.toString();
	}

}
